package com.snline.crm.logistics.action;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;

import com.snline.crm.logistics.entity.ProjectUser;
import com.snline.crm.logistics.service.LoginUserService;

public class LoginAction extends BaseAction {

	/**
	 * 序列化
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 用户信息
	 */
	private ProjectUser projectUser;
	
    @Value("${des.key}")
    private String key;  
    
	@Resource
	private LoginUserService loginUserService;
	
	/**
	 * 登录验证
	 * @return 处理结果
	 */
	public String login() {
		
		if (projectUser != null) {
		    
			projectUser = loginUserService.findProjectUser(projectUser);
			
		    if (projectUser == null) {
		        this.addActionError("用户名或密码错误！");
		        return ERROR;
		    } else {
		        session.put("userId", projectUser.getUserId());
                session.put("userName", projectUser.getUserName());
		    }
			return  SUCCESS;
		}
		this.addActionError("用户名或密码错误！");
		return ERROR;
	}
	
	/**
	 * 退出
	 * @return 处理结果
	 */
	public String logout() {
	    
	    session.clear();
	    return SUCCESS;
	}

	/**
	 * 注册用户
	 * @return
	 */
	public String registUser() {
	    
	    
	    return SUCCESS;
	}
	
	/**
	 * @return the projectUser
	 */
	public ProjectUser getProjectUser() {
		return projectUser;
	}

	/**
	 * @param projectUser the projectUser to set
	 */
	public void setProjectUser(ProjectUser projectUser) {
		this.projectUser = projectUser;
	}

	/**
	 * @return the loginUserService
	 */
	public LoginUserService getLoginUserService() {
		return loginUserService;
	}

	/**
	 * @param loginUserService the loginUserService to set
	 */
	public void setLoginUserService(LoginUserService loginUserService) {
		this.loginUserService = loginUserService;
	}
   
	
}
